// @before-stub-for-debug-begin
#include <vector>
#include <string>
#include "commoncppproblem75.h"

using namespace std;
// @before-stub-for-debug-end

/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\75.颜色分类.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-03-15 11:49:21
 * @Author: tianyiyi
 * @Copyright: Copyright@tianyiyi
 * @LastEditors: Mr.Tian
 * @LastEditTime: 2021-04-08 14:21:10
 */
/*
 * @lc app=leetcode.cn id=75 lang=cpp
 *
 * [75] 颜色分类
 */

// @lc code=start
class Solution {
public:
    void sortColors(vector<int>& nums) {
        //sort(nums.begin(),nums.end());
        int left = 0;
        int right = nums.size() - 1;
        for(int i = left;i <= right ; i++)
        {
            if(nums[i] == 0)
            {
                swap(nums,i,left);
                left++;
            }
            else if(nums[i] == 2)
            {
                swap(nums,i,right);
                right--;
                i--;
            }
            else
            {
                continue;
            }
        }
    }


    void swap(vector<int> &nums,int index,int targetIndex)
    {
        int temp = nums[index];
        nums[index] = nums[targetIndex];
        nums[targetIndex] = temp;
    }
};
// @lc code=end

